package me.samlss.lighter_demo.slice;

import me.samlss.lighter.Lighter;
import me.samlss.lighter.animator.AnimatorAttr;
import me.samlss.lighter.animator.CustomAnimatorValue;
import me.samlss.lighter.parameter.Direction;
import me.samlss.lighter.parameter.LighterParameter;
import me.samlss.lighter.parameter.MarginOffset;
import me.samlss.lighter.shape.OvalShape;
import me.samlss.lighter_demo.LighterHelper;
import me.samlss.lighter_demo.ResourceTable;
import me.samlss.lighter_demo.tools.Toast;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
/**
 * @author: zhu_zhonglin
 * @time: 2021/4/25
 */
public class ScrollViewAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    DependentLayout scroll_view_root;
    Image iv1, iv2, iv3, iv4, iv5, iv6, iv7;
    Text title_tv;
    private Image back_iv;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_scroll_view);
        initView();
        showGuide(iv2);
    }

    private void initView() {
        scroll_view_root = (DependentLayout) findComponentById(ResourceTable.Id_scroll_view_root);
        title_tv = (Text) findComponentById(ResourceTable.Id_title_tv);
        title_tv.setText("ScrollView");
        back_iv = (Image) findComponentById(ResourceTable.Id_back_iv);
        back_iv.setClickedListener(component -> getAbility().terminateAbility());
        iv1 = (Image) findComponentById(ResourceTable.Id_iv1);
        iv1.setClickedListener(this);
        iv2 = (Image) findComponentById(ResourceTable.Id_iv2);
        iv2.setClickedListener(this);
        iv3 = (Image) findComponentById(ResourceTable.Id_iv3);
        iv3.setClickedListener(this);
        iv4 = (Image) findComponentById(ResourceTable.Id_iv4);
        iv4.setClickedListener(this);
        iv5 = (Image) findComponentById(ResourceTable.Id_iv5);
        iv5.setClickedListener(this);
        iv6 = (Image) findComponentById(ResourceTable.Id_iv6);
        iv6.setClickedListener(this);
        iv7 = (Image) findComponentById(ResourceTable.Id_iv7);
        iv7.setClickedListener(this);
    }

    private void showGuide(Component highlightedView) {
        OvalShape ovalShape = new OvalShape();
        ovalShape.setPaint(LighterHelper.getDashPaint());

        if (highlightedView == null) {
            return;
        }
        Lighter.with(scroll_view_root, false)
                .setBackgroundColor(0x000000, 0.5f)
                .addHighlight(new LighterParameter.Builder()
                        .setHighlightedView(highlightedView)
                        .setTipLayoutId(ResourceTable.Layout_layout_tip_5)
                        .setTipViewRelativeDirection(Direction.TOP)
                        .setTipViewDisplayAnimation(new CustomAnimatorValue(new AnimatorAttr()))
                        .setLighterShape(ovalShape)
                        .build())
                .show();
    }

    @Override
    public void onActive() {
        super.onActive();
        Toast.show(getContext(),"Click to show highlight(点击显示高亮)~");
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        showGuide(component);
    }
}
